package com.boot.cluster.worker.bean;

import com.boot.cluster.enums.WorkState;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;


/***一项任务拆解到单个节点会有多个线程处理，只有全局调度器即任务中心才能分配计算任务 ***/
public class TaskSplitterInfo implements Serializable {

	private static final long serialVersionUID = 2544905861893789180L;

	/***同一id在单个节点上分成多个***/
	private String seq;
	private Long start;
	private Long end;
	private Integer page;
	private Integer pageSize;
	private Integer offset;
	/***附加参数****/
	private Map<String, Object> additional = new HashMap<>();
	private WorkState state = WorkState.WAITING;


	public TaskSplitterInfo(Long start, Long end) {
		this.start = start;
		this.end = end;
		this.seq = UUID.randomUUID().toString().replaceAll("-", "");
	}


	public TaskSplitterInfo(Integer pageSize, Integer page, Integer offset) {
		this.pageSize = pageSize;
		this.offset = offset;
		this.page = page;
		this.seq = UUID.randomUUID().toString().replaceAll("-", "");
	}

	public TaskSplitterInfo() {
		this.seq = UUID.randomUUID().toString().replaceAll("-", "");
	}

	public TaskSplitterInfo(String seq) {
		this.seq = seq;
	}
	public WorkState getState() {
		return this.state;
	}
	public void setState(WorkState state) {
		this.state = state;
	}
	public Long getStart() {
		return this.start;
	}

	public void setStart(Long start) {
		this.start = start;
	}

	public Long getEnd() {
		return this.end;
	}

	public void setEnd(Long end) {
		this.end = end;
	}
	public String getSeq() {
		return this.seq;
	}
	public void setSeq(String seq) {
		this.seq = seq;
	}
	public int getPage() {
		return this.page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getPageSize() {
		return this.pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}

	public int getOffset() {
		return this.offset;
	}

	public void setOffset(int offset) {
		this.offset = offset;
	}

	public Map<String, Object> getAdditional() {
		return this.additional;
	}

	public void setAdditional(Map<String, Object> additional) {
		this.additional = additional;
	}
}
